<template>
    <div class="card-page">
        <tool-bar nav="" :title='action_name + "权限页面按钮"'>
            <el-button size="small" @click="$router.push('/admin/admin-permission-page-action/add')" v-if="$props.action=='edit'">新建</el-button>
            <el-button size="small" @click="save_click" type="primary"> 保存</el-button>
        </tool-bar>
        <el-row :gutter="12" type="flex">
            <el-col :span="12">
                <el-card shadow="always">
                    <template #header>
                        <span>基本信息</span>
                    </template>
                    <kv label="name">
                        <el-input v-model="info.name" chk="*" />
                    </kv>
                    <kv label="action">
                        <el-input v-model="info.action" />
                    </kv>
                    <kv label="page">
                        <page-ref v-model="info.page"/>
                    </kv>
                </el-card>
            </el-col>
            <el-col :span="12">
                <el-card shadow="always">
                    <template #header>
                        <span>扩展信息</span>
                    </template>
                </el-card>
            </el-col>
        </el-row>
    </div>
</template>

<script setup>
/**
 * Created by CodeGenerator  at 2021-04-13 19:37:26
 */
import pageRef from "../admin-permission-page/admin-permission-page-ref.vue"




//定义 vue2的this,当前组件
const $self = getCurrentInstance();

//定义 $attrs
const $attrs = useAttrs();



//定义data
const $data = reactive({"info":{"page":{}}});
const info = $computed(()=> $data.info );

const $props = defineProps({
    action: { type: String } ,
    id : { type: String }
});



const list = ref();

//定义事件
const $emit = defineEmits(["update:modelValue","loaded"]);

const action = $computed( function() {
    return $props.id ? "edit" : "add";
});
const action_name = $computed( function() {
    return {add: "添加", edit: "修改"}[$props.action]
});

const loadData = function() {
    if (!$props.id) return;
    jv.$http.post("/admin/admin-permission-page-action/detail/" + $props.id).then(res => {
        $data.info = res.data.data;
    });
};
const save_click = function() {
//校验
    if (jv.chk_main() == false) {
        return;
    }
    jv.$http.post("/admin/admin-permission-page-action/save", $data.info).then(res => {
//[axios拦截器中已处理了异常]。
        jv.info(action_name + " 成功");
        if ($props.action == "add") {
            jv.$router.push("/admin/admin-permission-page-action/edit/" + res.data.data)
        } else if ($props.action == "edit") {
            jv.$router.push("/admin/admin-permission-page-action/list")
        }
    })
};

onMounted( function() {
    loadData();
} )



</script>
